<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>操作元素尺寸</title>
</head>

<body>
    <button id="btn">点击操作</button>
    <div id="boxid" style="width:100px;height:100px;"></div>
    <script>
        var eBtn = document.getElementById('btn');
        var box = document.getElementById('boxid');
        eBtn.onclick = function () {
            var box_W = box.style.width;
            var box_H = box.style.height;
            var box_nW = parseInt(box_W) + 20 + 'px';
            var box_nH = parseInt(box_H) + 20 + 'px';
            if (box.style.width >= '300px') {
                box.style.width = '300px';
                box.style.height = '300px';
            } else {
                box.style.width = box_nW;
                box.style.height = box_nH;
            }
        }
    </script>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #btn {
            width: 100px;
            height: 50px;
            border: 0;
            background-color: aqua;
            margin: 40px auto 20px auto;
            display: block;
        }

        #boxid {
            background-color: red;
            border: 0;
            margin: 0 auto;
        }
    </style>
</body>

</html>